/**
 * 
 */
package xiaojian.toolkit.fsm.predicate;

import java.util.Collection;

import org.apache.commons.collections4.Predicate;

/**
 * @author hp
 *
 */
public class TypeAcceptor implements Predicate<Object> {

	private	Collection<Class<?>>	allowTypes;
	
	/**
	 * @return the allowTypes
	 */
	public Collection<Class<?>> getAllowTypes() {
		return allowTypes;
	}

	/**
	 * @param allowTypes the allowTypes to set
	 */
	public void setAllowTypes(Collection<Class<?>> allowTypes) {
		this.allowTypes = allowTypes;
	}

	/* (non-Javadoc)
	 * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
	 */
	public boolean evaluate(Object object) {
		if ( null == object ) {
			return	false;
		}
		
		for ( Class<?> type : allowTypes ) {
			if ( type.isAssignableFrom(object.getClass()) ) {
				return	true;
			}
		}
		
		return	false;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "TypeAcceptor [allowTypes=" + allowTypes + "]";
	}

}
